package com.zju.DoctorGo.service.impl;

import com.zju.DoctorGo.entity.Medicine;
import com.zju.DoctorGo.mapper.MedicineMapper;
import com.zju.DoctorGo.service.MedicineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class MedicineServiceImpl implements MedicineService {

    @Autowired
    private MedicineMapper medicineMapper;

    @Override
    public Medicine createMedicine(Medicine medicine) {

        medicineMapper.addMedicine(medicine);

        medicine.setMedicineId(medicine.getMedicineId());
        return medicine;
    }

    @Override
    public Medicine updateMedicine(Long id, Medicine medicine) {
        medicine.setMedicineId(id);

        medicineMapper.updateMedicine(medicine);
        return medicine;
    }

    @Override
    public void deleteMedicine(Long id) {
        medicineMapper.deleteMedicine(id);
    }

    @Override
    public Medicine getMedicine(Long id) {
        Medicine medicine = medicineMapper.getMedicineById(id);
        return medicine;
    }

    @Override
    public List<Medicine> getAllMedicines() {
        List<Medicine> medicines = medicineMapper.getAllMedicines();
        return medicines;
    }
}
